package top.huhuiyu.demo.javaweb.util;

import java.util.Random;

public class RandUtil {

  public static Random random = new Random();
  public static final String CHARS = "abcdefghijklmnopqrstuvwxyz0123456789";
  public static final String CCHARS = "胡辉煜一二三四";

  public static int rand(int min, int max) {
    if (max < min) {
      throw new IllegalArgumentException("上届小于下届");
    }
    return random.nextInt(max - min + 1) + min;
  }

  public static String randStr(int len) {
    if (len < 1) {
      return "";
    }
    // 字符串构造器
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < len; i++) {
      // 在字符串中随机取一个字符
      int index = random.nextInt(CHARS.length());
      sb.append(CHARS.charAt(index));
    }
    return sb.toString();
  }

  public static String randCStr(int len) {
    if (len < 1) {
      return "";
    }
    // 字符串构造器
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < len; i++) {
      // 在字符串中随机取一个字符
      int index = random.nextInt(CCHARS.length());
      sb.append(CCHARS.charAt(index));
    }
    return sb.toString();
  }







}
